#!/bin/bash
#shell pro实现对于内核模块工程的
# 		创建 		create
# 		编译 		compile
# 		运行 		run 
# 		测试 		test
# 		调试 		debug
# 	  帮助 		help
########################################
# 注意：目前为止只能够每次执行上述的一个
#      后续可以实现这几个的组合;
#######################################
#version: 1.0
#date:    2015/10/14
#autor:   wangleijie
#######################################

#获取执行文件的文件名称;
filename="$0"
filename=${filename##*/}

print_all_help_info()
{
		./create -h
		./compile help 
		./run help 
		./test help 
		./debug help 
}

help()
{
	echo "====欢迎使用"$filename"的帮助功能===="
	if [ "$#" -eq 0 ]
	then
		echo "打印所有的帮助;"
		print_all_help_info
	else
		echo "循环打印"
		param_num=$(echo ""$#"+1"|bc)
		for((i=1; i<"$param_num";i++))
		do
			echo "$i"
			case $1 in 
				"create")
					./create -h
					;;
				"compile")
					echo "compile help"
					;;
				"run")
					echo "run help"
					;;
				"test")
					echo "test help"
					;;
				"debug")
					echo "debug help"
					;;
				*)
					echo "未知参数"
					;;
			esac
			shift
		done
	fi

}
#参数的个数;以及参数分析; 
param_list=""
get_param()
{
	if [ "$#" -lt 2 ] 
	then
		return 0 
	else
		shift
		param_num=$(echo ""$#"+1" |bc)
		for((i=1;i<="$param_num";i++))
		do
			param_list="$param_list"" ""$1"
			shift
		done
	fi
}

get_param "$@"

#主要的开始框架:
case "$1" in 
	"create")
		create "$param_list"
		;;
	"compile")
		echo "compile"
		;;
	"run")
		echo "run"
		;;
	"test")
		echo "test"
		;;
	"debug")
		echo "debug"
		;;
	"help")
		help
		;;
	*)
		help 
		;;
esac

